package com.witframework.core.resource;

import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ResourceBundleMessageSource;

import com.witframework.core.BeanFactory;

public class SpringResourceBundle {
	private static Log logger = LogFactory.getLog(SpringResourceBundle.class);

	ResourceBundleMessageSource resourceBundleMessageSource;
    private Locale locale;

    public void init(Locale locale) {
        this.locale = locale;
        resourceBundleMessageSource=(ResourceBundleMessageSource)BeanFactory.getBean("messageSource");
    }
    /**
     * Get the resource property.
     */
    public String getMessage(String code) {
        return getMessage(code, null);
    }

    /**
     * Get the resource property.
     */
    public String getMessage(String code, Object[] args) {
    	try{
    		String result=resourceBundleMessageSource.getMessage(code,args,code,locale);
    		 return result;
    	}catch(Exception e){
    		return code;
    	}

    }
}
